- title 'Users'
- content_for :head do
  = javascript_include_tag 'sections/users'
- content_for :title do
  = link_to "← Back to backlog settings", edit_account_backlog_path(@backlog.account, @backlog), :class => 'back'

- content_for :title do
  %h1= "Users for backlog #{@backlog.name}"

- if @account_users.blank?
  .page-notice
    There is an internal error as no users are registered for this account.
- else
  %h2.divider Permissions for users accessing this backlog
  %p
    Listed below are the users with access to this backlog, either set explicitly or inherited from the
    = link_to "account permissions", account_users_path(current_account)
    - if @backlog.company.present?
      or
      = link_to "or company permissions", account_company_users_path(current_account, @backlog.company)

  %form
    %table.users
      %tr
        %th Name
        %th Email address
        %th Permission
      - @account_users.each do |user_id, account_user|
        - select_id = "user-privilege-#{user_id}"
        %tr
          %td
            = label_tag select_id, account_user.user.name
          %td
            = label_tag select_id, account_user.user.email
          - if account_user.user == current_user || account_user.admin?
            %td
              .admin-access Administrator access to all features
          - else
            %td.privilege
              %select.privilege{ :id => select_id, :name => select_id }
                = raw privilege_options account_user, @backlog_users, 'this backlog'
            %td.action
              .progress-icon

%br
= link_to '← Back to backlog settings', edit_account_backlog_path(@backlog.account, @backlog), :class => 'button'